const app = new getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    default_img: '',
    user_info: {},
    listClickFlag: 0,
    logoutFlag: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that = this;
    
    app.restStatus(that, 'listClickFlag');
    app.restStatus(that, 'logoutFlag');
    app.defaultImg(that, true);
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  loadInfo: function () {
    let that = this;

    app.sendRequest({
      url: "System.Member.memberInfo",
      success: function (res) {
        let code = res.code;
        let data = res.data;

        if (code == 0) {
          let user_info = data.user_info;
          user_info.user_headimg = app.IMG(user_info.user_headimg); //图片路径处理
          that.setData({
            user_info: user_info
          })
        }
      }
    })
  },

  /**
   * 头像加载失败
   */
  errorHeadImg: function (e) {
    let that = this;
    let user_info = that.data.user_info;
    let default_img = that.data.default_img;
    let img = user_info.user_headimg;
    let parm = {};
    let parm_key = "user_info.user_headimg";

    if (default_img.is_use == 1 ) {
      default_img = default_img.value.default_headimg;
      if (img.indexOf(default_img) == -1) {
        parm[parm_key] = default_img;
        that.setData(parm);
      }
    }
  },
})